ass Solution {
public:
    vector<int> ans;
    void _preorderTraversal(TreeNode* root) 
    {
        if (root == nullptr)
        {
            return;
        }

        ans.push_back(root->val);
        _preorderTraversal(root->left);
        _preorderTraversal(root->right);
    }

    vector<int> preorderTraversal(TreeNode* root) 
    {
        _preorderTraversal(root);
        return ans;
    }
};
